// 转换后 A 数组只放正数，B 数组只放负数
// 双指针，从2个数组的开头开始双指针
const adjustment = (A, B) => {
  let l = 0;
  let r = 0;

  while (l < A.length && r < B.length) {
    while (A[l] > 0) {
      l++;
    }

    while (B[r] < 0) {
      r++;
    }

    if (A[l] != undefined && B[r] != undefined) {
      let temp = A[l];
      A[l] = B[r];
      B[r] = temp;
    }
  }
};
const A = [-4, 1, 10, 1, -8, 3, 6, -9, -1, -6, 7];
const B = [-4, -1, -8, -9, -1, 10, 3, 6, 1];

//adjustment(A, B);
//console.log(A, B);

// 双指针，从2边开始双指针就可以了
const arrayAdjustment = (A) => {
  let l = 0;
  r = A.length - 1;

  while (l < r) {
    while (A[l] < 0) {
      l++;
    }
    while (A[r] > 0) {
      r--;
    }
    if (l < r) {
      let temp = A[l];
      A[l] = A[r];
      A[r] = temp;
    }
  }
};

arrayAdjustment(A);

console.log(A);
